/**
 * Copyright (C) 2008 Christopher Allen Ogden
 *
 *     This file is part of Odysi.
 *
 *  Odysi is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Odysi is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Odysi.  If not, see <http://www.gnu.org/licenses/>.
 */
#pragma once
#include <string.h>
#include <boost/shared_array.hpp>

/**
 * Stores a packet of information.
 *
 * @author  Ogden, Chris
 */
class Packet
{
    public:
        /**
         * Default constructor.
         */
        Packet():_length(0)
        {
        }

        /**
         * Normal constructor.
         *
         * @param data      The data.
         * @param length    The length of the data.
         */
        Packet(const void * const data, size_t length)
        {
            setData(data, length);
        }

        /**
         * Sets the data of the packet.
         *
         * @param data      The data.
         * @param length    The length of the data.
         */
        void setData(const void * const data, size_t length)
        {
            _data = boost::shared_array<unsigned char>(new unsigned char[length]);
            _length = length;
            memcpy(_data.get(), data, length);
        }

        /**
         * Get the data.
         *
         * @return  A pointer to the data.
         */
        const void * const getData(void) const
        {
            return _data.get();
        }

        /**
         * Get the length of the packet.
         *
         * @return  The length.
         */
        size_t getLength(void) const
        {
            return _length;
        }

    private:
        // The length of the data.
        size_t _length;

        // The actual data.
        boost::shared_array<unsigned char> _data;
};
